package com.stray.crawl.expr.psr;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Locale;

import com.stray.crawl.excp.ParseOperationException;
import com.stray.crawl.expr.Express;

public class DateParser extends Express {

	@Override
	protected Object doParse(Object obj, String args) {
		try {
			String str = (String) obj;

			String dateForamt = args.contains("\\") ? args.replace('\\', '/') : args;
			SimpleDateFormat format = new SimpleDateFormat(dateForamt, Locale.US);

			return format.parse(str);
		} catch (ParseException ex) {
			throw new ParseOperationException("Invalid date time format. ", ex);
		}

	}

}